import komand
from .schema import LookupVulnerabilityInput, LookupVulnerabilityOutput


class LookupVulnerability(komand.Action):
    def __init__(self):
        super(self.__class__, self).__init__(
            name="lookup_vulnerability",
            description="This action is used to fetch information about a specific vulnerability by CVE or RF ID",
            input=LookupVulnerabilityInput(),
            output=LookupVulnerabilityOutput(),
        )

    def run(self, params={}):
        try:
            vulnerability_ID = params.get("id")
            vulnerability_report = self.connection.client.lookup_vulnerability(
                vulnerability_ID
            )
            return vulnerability_report
        except Exception as e:
            self.logger.error("Error: " + str(e))
